<?php if (isset($members)) {  
    //var_dump($members[0])
    ?>

    

    <div class="row-fluid " style=" margin-bottom: 20px;  margin-top: 20px;">
        <div class="span12">
            <div class="span7">
                <h1><?php echo '<h1>Proyecto :' ;

                    echo $this->Html->link(h($defaultTeam['Project']['name']),'view/'.$defaultTeam['Project']['id']);
                ?>
                <a href="<?php echo $this->base.'/projects/role/'.$defaultTeam['Project']['id']; ?>" role="button"  ><i class="icon-wrench"></i></a>
                </h1>
                
                <p><small>Created: <?php echo $defaultTeam['Project']['created']; ?></small></p>

            </div> 

            <div class="span5" align="right">
                <?php if ($permiso){ ?>
                <?php echo $this->Form->create(null,array('url'=> 'members/'.$defaultTeam['Team']['id'].'/find','class'=>'form-search','inputDefaults' => array('label' => false ,'div' => false,'class'=>'input')));
                        echo "<div class='input-append'>";

                        echo $this->Form->input('buscar',array('class'=>'span8 search-query','placeholder'=>'Agregar un usuario')); ?>
                        <button type="submit" class="btn"><i class="icon-search"></i></button>
                <?php echo '</div></form>'; ?>
                <?php } ?>        
             </div>
            
        <!-- Button to trigger modal -->
<!--        <a data-toggle="modal" href="#addMember" class="btn btn-small btn-inverse " role="button"  ><i class="icon-plus-sign icon-white"></i> Nueva</a>-->
        <!-- Modal -->
        
            <div id="addMember" 
                class="modal hide fade<?php if (isset($users)) echo " in";?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"  aria-hidden="<?php if (isset($users)) echo "true"; else echo "false";?>"
                <?php if (isset($users)) echo 'style="display: block;"'; else echo'style="display: none;"';?>  >

                    <div class="modal-header">
            <!--            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>-->
                        <a class="close " href="<?php echo $this->base;?>/projects/members/<?php echo $defaultTeam['Project']['id'] ;?>" >x</a>
                        <h3 id="myModalLabel">Elegir Miembro</h3>
                    </div>
                    <div class="modal-body">
                        <?php if (count($users)>0){?>
                        <table class="table table-striped">

                            <tbody > 
                                <?php for ($i=0;$i<count($users);$i++){?>
                                <tr>
                                    <td>
                                        <strong><?php echo $users[$i]['User']['username']; ?></strong>
                                    </td>
                                    <td>
                                        <?php 
                                            echo $this->Form->create('Member',array('url'=> '../members/add/'.$defaultTeam['Team']['id'].'/1','class'=>'form-inline','inputDefaults' => array('hiddenField' => false,'label' => false ,'div' => false)));
                                            echo $this->Form->hidden('user_id',array('value'=>$users[$i]['User']['id'])); ?>
                                            <button type="submit" class="btn btn-success btn-small" >Agregar</button>
                                            <?php echo '</form>'; ?>

                                    </td>
                                </tr>
                                <?php } ?>
                            </tbody>

                        </table>
                        <?php } else {?>
                            <div class="alert">
                                No se encontraron usuarios.
                            </div>
                        <?php }?>
                    </div>
                    <div class="modal-footer">
                        <div aling="right">
                            <a class="btn" href="<?php echo $this->base;?>/projects/members/<?php echo $defaultTeam['Project']['id'] ;?>" >Cancelar</a>
                        </div>

                    </div>
            </div>
            
            

        </div>
        <div class="span12">
            
        </div>
    </div>
    
        
        
    <!--    MEMBERS!-->
    <?php if (count($members)>0)  {?>
        <table class="table table-hover">
       <?php for ($i = 0; $i < count($members); $i++) { ?>
            <tr>
                <td>
                    <?php
                    $size=50;
                    $hash=$members[$i]['User']['gravatar'];
                    echo '<img src=http://www.gravatar.com/avatar/'.$hash.'?s='.$size.'&amp;default='.
                                                    urlencode('http://www.gravatar.com/avatar/ad516503a11cd5ca435acc9bb6523536?s='.$size).'>';

                    ?>
                    
                </td>
                <td>
                    <?php echo $members[$i]['User']['username']; ?>
                </td>
                <td>
                    <?php
                    if (is_null($members[$i]['ProjectMember']['role_id']))
                        echo '<span class="label label-important">Sin rol!</span>';
                    else{
                        $label =  "label-default";
                        if ($members[$i]['Role']['description']=="ScrumMaster") $label =  "label-success";
                        if ($members[$i]['Role']['description']=="Propietario") $label =  "label-info";
                        if ($members[$i]['Role']['description']=="Equipo") $label =  "label-inverse";
                        
                        echo '<span class="label '.$label.'">'.$members[$i]['Role']['description'].'</span>';
                    }
                    ?>
                     <a data-toggle="modal" href="#editRole<?php echo $members[$i]['ProjectMember']['user_id'] ?>" role="button"  ><i class="icon-edit"></i></a>
                        <?php
                            echo $this->element('members/editRole',array("member" => $members[$i],"roles" =>$roles));

                        ?>
                </td>
<!--                <td>

                        <?php echo $this->Form->postLink(
                                    '<i class="icon-trash"></i>', //le image
                                    '/members/delete/'.$members[$i]['ProjectMember']['user_id'].'/'.$members[$i]['ProjectMember']['team_id'], //,le url
                                    array('escape' => false,'confirm' => 'Are you sure?','class' => 'nav-pills'));

                         ?>
                </td>-->
            <tr/>
            

    <?php  } ?>
    </table>
        <?php }   else { ?>
        <div class="alert">
            <button type="button" class="close" data-dismiss="alert">×</button>
            No ha ingresado ningún miembro.
        </div>
    <?php }
    if (isset($users))
        echo '<div class="modal-backdrop fade in"></div>';
    
    ?>
    
   
    <?php } else {?>
    <br/>
    <div class="alert alert-info">
        Error de acceso.
    </div>
<?php }?>


